//package com.example.springbootlinmtest.utils;
//
//import com.alibaba.excel.context.AnalysisContext;
//import com.alibaba.excel.read.listener.ReadListener;
//import com.example.springbootlinmtest.pojo.UserInfo;
//import lombok.extern.slf4j.Slf4j;
//import com.alibaba.excel.util.ListUtils;
//
//import java.util.List;
//
//// 有个很重要的点 DemoDataListener 不能被spring管理，要每次读取excel都要new,然后里面用到spring可以构造方法传进去
//@Slf4j
//public class DemoDataListener implements ReadListener<UserInfo> {
//
////    /**
////     * 每隔5条存储数据库，实际使用中可以100条，然后清理list ，方便内存回收
////     */
////    private static final int BATCH_COUNT = 100;
////    /**
////     * 缓存的数据
////     */
////    private List<UserInfo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
////
////   UserInfoMapper userInfoMapper;
////   String flag;
////    public DemoDataListener(UserInfoMapper userInfoMapper,String flag) {
////        this.userInfoMapper = userInfoMapper;
////        this.flag = flag;
////    }
////
////
////    /**
////     * 这个每一条数据解析都会来调用
////     *
////     * @param data    one row value. Is is same as {@link AnalysisContext#readRowHolder()}
////     */
////    @Override
////    public void invoke(UserInfo data, AnalysisContext context) {
////        //log.info("解析到一条数据:{}", JSON.toJSONString(data));
////
////        data.setFlag(flag);
////        cachedDataList.add(data);
////        // 达到BATCH_COUNT了，需要去存储一次数据库，防止数据几万条数据在内存，容易OOM
////        if (cachedDataList.size() >= BATCH_COUNT) {
////            log.info("解析的数据量=={}",cachedDataList.size());
////            // 存储完成清理 list
////            //log.info(cachedDataList.toString());
////            userInfoMapper.batchInsert(cachedDataList);
////            cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
////        }
////    }
////
////    /**
////     * 所有数据解析完成了 都会来调用
////     *
////     */
////    @Override
////    public void doAfterAllAnalysed(AnalysisContext context) {
////        // 这里也要保存数据，确保最后遗留的数据也存储到数据库
////        userInfoMapper.batchInsert(cachedDataList);
////        log.info("所有数据解析完成！");
////    }
//
//
//
//}